<!--
 * @FilePath     : /layui/demo/1131.html
 * @Description  : 表单提交自动赋值
 * @Date         : 2025-02-21 08:36
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-02-21 08:39
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
    <link rel="stylesheet" href="/layui/extends_modules/formSelects-v4/formSelects-v4.css" />
  </head>
  <body>
    <div class="layui-form">
      <select name="city" xm-select="select11" lay-verify="required" lay-verType="tips">
        <option value="1">北京</option>
        <option value="2">上海</option>
        <option value="3" selected="selected">广州</option>
        <option value="4">深圳</option>
        <option value="5" selected="selected">天津</option>
        <option value="6">杭州</option>
      </select>

      <button lay-submit lay-filter="subone">提交</button>
    </div>

    <script src="/layui/dist/layui.js"></script>
    <script>
      layui
        .config({
          base: '/layui/extends_modules/', // 配置 layui 第3方扩展模块存放的基础目录
        })
        .extend({
          formSelects: '/formSelects-v4/formSelects-v4',
        })
        .use(['jquery', 'formSelects'], function () {
          var $ = layui.jquery,
            formSelects = layui.formSelects,
            form = layui.form

          //
          form.on('submit(subone)', function (data) {
          console.log('one')
          // console.log(data.elem)
          // console.log(data.form)
          console.log(data.field)
          /*
          获取到值
          {
            city: '3, 5',
          }
          */
          return false // ！阻止表单提交时的跳转。如果需要表单跳转，去掉这段即可。
        })
        })
    </script>
  </body>
</html>
